package suanfarumen;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class day11 {
    public static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> target=new ArrayList<>();
        Deque<Integer> stack =new ArrayDeque<>();
        dfs(n,k,1,stack,target);
        return target;
    }
    private static void dfs(int n, int k, int begin, Deque<Integer> stack, List<List<Integer>> target) {
        if (stack.size()==k){
            target.add(new ArrayList<>(stack));
            return;
        }
        for (int i=begin;i<=n - (k - stack.size()) + 1;i++){
            stack.addLast(i);
            dfs(n,k,i+1,stack,target);
            stack.removeLast();
        }

    }
    public static void main(String[] args) {

        System.out.println(combine(4,2));
    }
}
